﻿namespace YAF.Modules
{
    using System.Collections.Generic;
    using System.Reflection;
    using System.Web.Compilation;

    public class YafBaseModuleManager : YafModuleManager<IBaseModule>
    {
        protected bool _initCalled = false;

        private YafBaseModuleManager()
            : base("YAF.Modules", "YAF.Modules.IBaseModule")
        {
            if (this.ModuleClassTypes == null)
            {
                this.AddModules(
                    new List<Assembly>() { 
                        Assembly.GetExecutingAssembly()
                    });

                this.AddModules(BuildManager.CodeAssemblies);
            }
        }

        public void CallInitModules(object forumControl)
        {
            if (!this._initCalled)
            {
                foreach (IBaseModule currentModule in this.Modules)
                {
                    currentModule.ForumControlObj = forumControl;
                    currentModule.Init();
                }

                this._initCalled = true;
            }
        }
    }
}
